package com.kersci.heartratereader

import android.app.Application
import com.clj.fastble.BleManager
import com.kersci.heartratereader.utils.DeviceManager
import com.kersci.heartratereader.utils.Logger
import kotlin.properties.Delegates

class App : Application() {
    companion object {
        var instance: App by Delegates.notNull<App>()
    }

    private lateinit var deviceManager: DeviceManager

    override fun onCreate() {
        super.onCreate()
        BleManager.getInstance().init(this)
        BleManager.getInstance().enableLog(true)
            .setReConnectCount(1, 5000)
            .operateTimeout = 10000

        deviceManager = DeviceManager()
        Logger.init()
        instance = this
    }

    public fun getDeviceManager(): DeviceManager {
        return deviceManager
    }

    override fun onTerminate() {
        super.onTerminate()
        deviceManager.clear()
    }
}